Principal Component Analysis
# https://www.rpubs.com/twyunting/PCA_in_the_tidyverse_Framework
# https://stackoverflow.com/questions/73786208/ggbiplot-how-to-change-the-colour-of-the-arrows-and-text-using-a-function-for
# PCA for business variables:
# customers,fulls,halfs,takeouts,liquors,sales
pca_bus <- df %>%
filter(is_closed == FALSE) %>%
select(c(customers,fulls,halfs,takeouts,liquors,sales)) %>%
prcomp()
pca_bus
## Standard deviations (1, .., p=6):
## [1] 214.732100 7.765591 3.696578 3.444734 1.566496 1.184341
##
## Rotation (n x k) = (6 x 6):
## PC1 PC2 PC3 PC4 PC5
## customers -0.040159987 0.65415860 0.53926876 0.003558498 0.060251895
## fulls -0.029860294 0.54164943 -0.15786373 0.636260658 0.041233236
## halfs -0.007547398 0.08289829 0.54937299 -0.489499360 0.050317942
## takeouts -0.015212980 -0.51993282 0.60713716 0.592751376 0.096986947
## liquors -0.003971133 -0.01596434 -0.11378519 -0.060061003 0.991282881
## sales -0.998594698 -0.03514675 -0.02991606 -0.024260491 -0.009455986
## PC6
## customers 0.5253664932
## fulls -0.5237131815
## halfs -0.6701632001
## takeouts 0.0078888164
## liquors 0.0230916594
## sales -0.0006150708
# Visualization ----
# the first principal direction (PC1) space
pca_bus %>%
tidy(matrix = "loadings") %>%
filter(PC == 1) %>%
ggplot(aes(value, column)) +
geom_col() +
theme_bw()

# each pc space
pca_bus %>%
tidy(matrix = "loadings") %>%
ggplot(aes(value, column)) +
geom_col() +
facet_wrap(~PC)

# Variance explained
pca_bus %>%
tidy(matrix = "pcs") %>%
ggplot(aes(PC, percent)) +
geom_col() +
theme_bw() +
scale_x_continuous(breaks = 1:8) +
scale_y_continuous(
labels = scales::percent_format(),
expand = expansion(mult = c(0, 0.01))
)

ggbiplot(pca_bus)

# PCA for weather terms:
# temperature, humidity, precipitation
pca_weather <- df %>%
filter(is_closed == FALSE) %>%
select(c(temp_c,humi_p,prcp_mm)) %>%
prcomp()
pca_weather
## Standard deviations (1, .., p=3):
## [1] 11.97351 9.37176 1.99279
##
## Rotation (n x k) = (3 x 3):
## PC1 PC2 PC3
## temp_c 0.19339715 0.9809830 0.01643034
## humi_p 0.97919789 -0.1919432 -0.06579745
## prcp_mm 0.06139248 -0.0288136 0.99769772
# Visualization ----
# the first principal direction (PC1) space
pca_weather %>%
tidy(matrix = "loadings") %>%
filter(PC == 1) %>%
ggplot(aes(value, column)) +
geom_col() +
theme_bw()

# each pc space
pca_weather %>%
tidy(matrix = "loadings") %>%
ggplot(aes(value, column)) +
geom_col() +
facet_wrap(~PC)

# Variance explained
pca_weather %>%
tidy(matrix = "pcs") %>%
ggplot(aes(PC, percent)) +
geom_col() +
theme_bw() +
scale_x_continuous(breaks = 1:8) +
scale_y_continuous(
labels = scales::percent_format(),
expand = expansion(mult = c(0, 0.01))
)

ggbiplot(pca_weather)

Scatter Plot
FW with temp
# food waste and temperature ---------------------
scatter_waste_temp <-
ggplot(subset(df,is_closed==FALSE),
aes(x=temp_c, y=food_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Food Waste (kg)",
limits = c(0, 7), expand = c(0, 0)) +
scale_x_continuous(name = "Daily Temperature (Degree Celsius)",
limits = c(-40, 15), expand = c(0, 0)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
#scatter_waste_temp
dens_temp <-
ggplot(subset(df,is_closed==FALSE), aes(x = temp_c)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_temp
dens_waste <-
ggplot(subset(df,is_closed==FALSE), aes(x = food_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_dens_waste_temp <-
dens_temp +
labs(title = "Scatter and Kernel Densities of Food Waste with Temperature (°C)") +
plot_spacer() + # library(patchwork)
scatter_waste_temp + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_dens_waste_temp

rm("dens_waste","dens_temp","scatter_waste_temp")
# solid food waste and temperature ---------------
scatter_waste_temp <-
ggplot(subset(df,is_closed==FALSE),aes(x=temp_c, y=solid_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Food Waste (kg)",
limits = c(0, 3), expand = c(0, 0)) +
scale_x_continuous(name = "Daily Temperature (Degree Celsius)",
limits = c(-40, 15), expand = c(0, 0)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
#scatter_waste_temp
dens_temp <-
ggplot(subset(df,is_closed==FALSE), aes(x = temp_c)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_temp
dens_waste <-
ggplot(subset(df,is_closed==FALSE), aes(x = food_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_dens_solid_waste_temp <-
dens_temp +
labs(title = "Scatter and Kernel Densities of Solid Food Waste with Temperature (°C)") +
plot_spacer() + # library(patchwork)
scatter_waste_temp + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_dens_solid_waste_temp

rm("dens_waste","dens_temp","scatter_waste_temp")
# liquid food waste and temperature --------------
scatter_waste_temp <-
ggplot(subset(df,is_closed==FALSE),aes(x=temp_c, y=liquid_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Food Waste (kg)",
limits = c(0, 5), expand = c(0, 0)) +
scale_x_continuous(name = "Daily Temperature (Degree Celsius)",
limits = c(-40, 15), expand = c(0, 0)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
#scatter_waste_temp
dens_temp <-
ggplot(subset(df,is_closed==FALSE), aes(x = temp_c)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_temp
dens_waste <-
ggplot(subset(df,is_closed==FALSE), aes(x = food_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_dens_liquied_waste_temp <-
dens_temp +
labs(title = "Scatter and Kernel Densities of Liquid Food Waste with Temperature (°C)") +
plot_spacer() + # library(patchwork)
scatter_waste_temp + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_dens_liquied_waste_temp

rm("dens_waste","dens_temp","scatter_waste_temp")
FW with humidity
# food waste and humidity ---------------------
scatter_waste_humi <-
ggplot(subset(df,is_closed==FALSE),aes(x=humi_p, y=food_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Food Waste (kg)",
limits = c(0, 7), expand = c(0, 0)) +
scale_x_continuous(name = "Daily Humidity (Percent)",
limits = c(50, 100), expand = c(0, 0)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
# scatter_waste_humi
dens_humi <-
ggplot(subset(df,is_closed==FALSE), aes(x = humi_p)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_humi
dens_waste <-
ggplot(subset(df,is_closed==FALSE), aes(x = food_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_dens_waste_humi <-
dens_humi +
labs(title = "Scatter and Kernel Densities of Food Waste with Humidity (%)") +
plot_spacer() + # library(patchwork)
scatter_waste_humi + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_dens_waste_humi

rm("dens_waste","dens_humi","scatter_waste_humi")
# solid food waste and humidity ---------------
scatter_waste_humi <-
ggplot(subset(df,is_closed==FALSE),aes(x=humi_p, y=solid_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Food Waste (kg)",
limits = c(0, 3), expand = c(0, 0)) +
scale_x_continuous(name = "Daily Humidity (Percent)",
limits = c(50, 100), expand = c(0, 0)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
#scatter_waste_humi
dens_humi <-
ggplot(subset(df,is_closed==FALSE), aes(x = humi_p)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_humi
dens_waste <-
ggplot(subset(df,is_closed==FALSE), aes(x = solid_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_dens_solid_waste_humi <-
dens_humi +
labs(title = "Scatter and Kernel Densities of Solid Food Waste with Humidity (%)") +
plot_spacer() + # library(patchwork)
scatter_waste_humi + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_dens_solid_waste_humi

rm("dens_waste","dens_humi","scatter_waste_humi")
# liquid food waste and humidity --------------
scatter_waste_humi <-
ggplot(subset(df,is_closed==FALSE),aes(x=humi_p, y=liquid_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Food Waste (kg)",
limits = c(0, 5), expand = c(0, 0)) +
scale_x_continuous(name = "Daily Humidity (Percent)",
limits = c(50, 100), expand = c(0, 0)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
#scatter_waste_humi
dens_humi <-
ggplot(subset(df,is_closed==FALSE), aes(x = humi_p)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_humi
dens_waste <-
ggplot(subset(df,is_closed==FALSE), aes(x = liquid_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_dens_liquied_waste_humi <-
dens_humi +
labs(title = "Scatter and Kernel Densities of Liquid Food Waste with Humidity (%)") +
plot_spacer() + # library(patchwork)
scatter_waste_humi + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_dens_liquied_waste_humi

rm("dens_waste","dens_humi","scatter_waste_temp")
## Warning in rm("dens_waste", "dens_humi", "scatter_waste_temp"): object
## 'scatter_waste_temp' not found
FW with precipitation
# food waste and humidity ------------------------
scatter_waste_precip <-
ggplot(subset(df,is_closed==FALSE),aes(x=prcp_mm, y=food_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Food Waste (kg)",
limits = c(-10, 10), expand = c(0.05, 0)) +
scale_x_continuous(name = "Daily Precipitation (mm)",
limits = c(-15, 15), expand = c(0.05, 0)) +
coord_cartesian(xlim=c(0,15), ylim=c(0,7)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
#scatter_waste_precip
dens_precip <-
ggplot(subset(df,is_closed==FALSE), aes(x = prcp_mm)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_precip
dens_waste <-
ggplot(subset(df,is_closed==FALSE), aes(x = food_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_dens_precip <-
dens_precip +
labs(title = "Scatter and Kernel Densities of Food Waste and Precipitation (mm)") +
plot_spacer() + # library(patchwork)
scatter_waste_precip + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_dens_precip

# Solid food waste and humidity ------------------------
scatter_waste_precip <-
ggplot(subset(df,is_closed==FALSE),aes(x=prcp_mm, y=solid_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Solid Food Waste (kg)",
limits = c(-10, 10), expand = c(0.05, 0)) +
scale_x_continuous(name = "Daily Precipitation (mm)",
limits = c(-15, 15), expand = c(0.05, 0)) +
coord_cartesian(xlim=c(0,15), ylim=c(0,3)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
#scatter_waste_precip
dens_precip <-
ggplot(subset(df,is_closed==FALSE), aes(x = prcp_mm)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_precip
dens_waste <-
ggplot(subset(df,is_closed==FALSE), aes(x = solid_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_solid_precip <-
dens_precip +
labs(title = "Scatter and Kernel Densities of Solid Food Waste and Precipitation (mm)") +
plot_spacer() + # library(patchwork)
scatter_waste_precip + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_solid_precip

# Liquid food waste and humidity ------------------------
scatter_waste_precip <-
ggplot(subset(df,is_closed==FALSE),aes(x=prcp_mm, y=liquid_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Solid Food Waste (kg)",
limits = c(-10, 10), expand = c(0.05, 0)) +
scale_x_continuous(name = "Daily Precipitation (mm)",
limits = c(-15, 15), expand = c(0.05, 0)) +
coord_cartesian(xlim=c(0,15), ylim=c(0,6)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
#scatter_waste_precip
dens_precip <-
ggplot(subset(df,is_closed==FALSE), aes(x = prcp_mm)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_precip
dens_waste <-
ggplot(subset(df,is_closed==FALSE), aes(x = liquid_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_liquid_precip <-
dens_precip +
labs(title = "Scatter and Kernel Densities of Liquid Food Waste and Precipitation (mm)") +
plot_spacer() + # library(patchwork)
scatter_waste_precip + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_liquid_precip

rm("dens_waste","dens_precip","scatter_waste_precip")
FW with customers
# food waste and customer ------------------------
scatter_waste_customer <-
ggplot(subset(df,is_closed==FALSE),
aes(x=customers, y=food_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Food Waste (kg)",
limits = c(-10, 10), expand = c(0.05, 0)) +
scale_x_continuous(name = "Daily Number of Customers",
limits = c(0, 60), expand = c(0.05, 0)) +
coord_cartesian(xlim=c(0,50), ylim=c(0,7)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
#scatter_waste_customer
dens_customer <-
ggplot(subset(df,is_closed==FALSE), aes(x = customers)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_customer
dens_waste <-
ggplot(subset(df,is_closed==FALSE), aes(x = food_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_dens_customer <-
dens_customer +
labs(title = "Scatter and Kernel Densities of Food Waste and Customers") +
plot_spacer() + # library(patchwork)
scatter_waste_customer + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_dens_customer

# solid food waste and customer ------------------------
scatter_waste_customer <-
ggplot(subset(df,is_closed==FALSE),
aes(x=customers, y=solid_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Solid Food Waste (kg)",
limits = c(-10, 10), expand = c(0.05, 0)) +
scale_x_continuous(name = "Daily Number of Customers",
limits = c(0, 60), expand = c(0.05, 0)) +
coord_cartesian(xlim=c(0,50), ylim=c(0,3)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
#scatter_waste_customer
dens_customer <-
ggplot(subset(df,is_closed==FALSE), aes(x = customers)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_customer
dens_waste <-
ggplot(subset(df,is_closed==FALSE), aes(x = solid_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_solid_customer <-
dens_customer +
labs(title = "Scatter and Kernel Densities of Solid Food Waste and Customers") +
plot_spacer() + # library(patchwork)
scatter_waste_customer + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_solid_customer

# liquid food waste and customer ------------------------
scatter_waste_customer <-
ggplot(subset(df,is_closed==FALSE),
aes(x=customers, y=liquid_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Liquid Food Waste (kg)",
limits = c(-10, 10), expand = c(0.05, 0)) +
scale_x_continuous(name = "Daily Number of Customers",
limits = c(0, 60), expand = c(0.05, 0)) +
coord_cartesian(xlim=c(0,50), ylim=c(0,6)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
#scatter_waste_customer
dens_customer <-
ggplot(subset(df,is_closed==FALSE), aes(x = customers)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_customer
dens_waste <-
ggplot(subset(df,is_closed==FALSE),
aes(x = liquid_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_liquid_customer <-
dens_customer +
labs(title = "Scatter and Kernel Densities of Liquid Food Waste and Customers") +
plot_spacer() + # library(patchwork)
scatter_waste_customer + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_liquid_customer

rm("dens_waste","dens_customer","scatter_waste_customer")
FW with sales
# food waste and sales ------------------------
scatter_waste_sales <-
ggplot(subset(df,is_closed==FALSE),
aes(x=sales, y=food_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Food Waste (kg)",
limits = c(-10, 10), expand = c(0.05, 0)) +
scale_x_continuous(name = "Daily Sales (CAD)",
limits = c(0, 1300), expand = c(0.05, 0)) +
coord_cartesian(xlim=c(0,1300), ylim=c(0,7)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
#scatter_waste_sales
dens_sales <-
ggplot(subset(df,is_closed==FALSE), aes(x = sales)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_sales
dens_waste <-
ggplot(subset(df,is_closed==FALSE), aes(x = food_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_dens_sales <-
dens_sales +
labs(title = "Scatter and Kernel Densities of Food Waste and Customers") +
plot_spacer() + # library(patchwork)
scatter_waste_sales + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_dens_sales

# solid food waste and sales ------------------------
scatter_waste_sales <-
ggplot(subset(df,is_closed==FALSE),
aes(x=sales, y=solid_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Food Waste (kg)",
limits = c(-10, 10), expand = c(0.05, 0)) +
scale_x_continuous(name = "Daily Sales (CAD)",
limits = c(0, 1300), expand = c(0.05, 0)) +
coord_cartesian(xlim=c(0,1300), ylim=c(0,4)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
#scatter_waste_sales
dens_sales <-
ggplot(subset(df,is_closed==FALSE), aes(x = sales)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_sales
dens_waste <-
ggplot(subset(df,is_closed==FALSE), aes(x = solid_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_solid_sales <-
dens_sales +
labs(title = "Scatter and Kernel Densities of Solid Food Waste and Customers") +
plot_spacer() + # library(patchwork)
scatter_waste_sales + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_solid_sales

# solid food waste and sales ------------------------
scatter_waste_sales <-
ggplot(subset(df,is_closed==FALSE),
aes(x=sales, y=liquid_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Food Waste (kg)",
limits = c(-10, 10), expand = c(0.05, 0)) +
scale_x_continuous(name = "Daily Sales (CAD)",
limits = c(0, 1300), expand = c(0.05, 0)) +
coord_cartesian(xlim=c(0,1300), ylim=c(0,3)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
#scatter_waste_sales
dens_sales <-
ggplot(subset(df,is_closed==FALSE), aes(x = sales)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_sales
dens_waste <-
ggplot(subset(df,is_closed==FALSE), aes(x = liquid_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_liquid_sales <-
dens_sales +
labs(title = "Scatter and Kernel Densities of Liquid Food Waste and Customers") +
plot_spacer() + # library(patchwork)
scatter_waste_sales + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_liquid_sales

rm("dens_waste","dens_sales","scatter_waste_sales")
FW with liquor
# food waste and liquor ------------------------
scatter_waste_liquor <-
ggplot(subset(df,is_closed==FALSE),
aes(x=liquors, y=food_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Food Waste (kg)",
limits = c(-10, 10), expand = c(0.05, 0)) +
scale_x_continuous(name = "Daily Liquor Sold",
limits = c(0, 10), expand = c(0.01, 0)) +
coord_cartesian(xlim=c(0,8), ylim=c(0,7)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
#scatter_waste_liquor
dens_liquor <-
ggplot(subset(df,is_closed==FALSE), aes(x = liquors)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_liquor
dens_waste <-
ggplot(subset(df,is_closed==FALSE),
aes(x = food_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_dens_liquor <-
dens_liquor +
labs(title = "Scatter and Kernel Densities of Food Waste and Liquor") +
plot_spacer() + # library(patchwork)
scatter_waste_liquor + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_dens_liquor

# solid food waste and liquor ------------------------
scatter_waste_liquor <-
ggplot(subset(df,is_closed==FALSE),
aes(x=liquors, y=solid_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Solid Food Waste (kg)",
limits = c(-10, 10), expand = c(0.05, 0)) +
scale_x_continuous(name = "Daily Liquor Sold",
limits = c(0, 10), expand = c(0.01, 0)) +
coord_cartesian(xlim=c(0,8), ylim=c(0,3)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
#scatter_waste_liquor
dens_liquor <-
ggplot(subset(df,is_closed==FALSE), aes(x = liquors)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_liquor
dens_waste <-
ggplot(subset(df,is_closed==FALSE),
aes(x = solid_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_solid_liquor <-
dens_liquor +
labs(title = "Scatter and Kernel Densities of Solid Food Waste and Liquor") +
plot_spacer() + # library(patchwork)
scatter_waste_liquor + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_solid_liquor

# liquid food waste and liquor ------------------------
scatter_waste_liquor <-
ggplot(subset(df,is_closed==FALSE),
aes(x=liquors, y=liquid_waste_kg)) +
geom_point(size = 2) +
geom_point(shape = 1, color = "black", size = 2) +
geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
geom_rug() +
scale_y_continuous(name = "Daily Liquid Food Waste (kg)",
limits = c(-10, 10), expand = c(0.05, 0)) +
scale_x_continuous(name = "Daily Liquor Sold",
limits = c(0, 10), expand = c(0.01, 0)) +
coord_cartesian(xlim=c(0,8), ylim=c(0,3)) +
theme_pubr() +
theme(legend.position = c(0.15, 0.9))
#scatter_waste_liquor
dens_liquor <-
ggplot(subset(df,is_closed==FALSE), aes(x = liquors)) +
geom_density(color="black", fill="grey") +
scale_fill_grey() +
theme_void() +
theme(legend.position = "none")
#dens_liquor
dens_waste <-
ggplot(subset(df,is_closed==FALSE),
aes(x = liquid_waste_kg), fill = "dark") +
geom_density(color="black", fill="grey") +
theme_void() +
theme(legend.position = "none") +
coord_flip()
#dens_waste
scatter_liquid_liquor <-
dens_liquor +
labs(title = "Scatter and Kernel Densities of Food Waste and Liquor") +
plot_spacer() + # library(patchwork)
scatter_waste_liquor + dens_waste +
plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))
scatter_liquid_liquor

rm("dens_waste","dens_liquor","scatter_waste_liquor")